package com.zmykj.hik.hikService.Controllers;

import com.alibaba.fastjson.JSONObject;
import com.zmykj.hik.common.AjaxResult;
import com.zmykj.hik.hikService.Common.CommonClass;
import com.zmykj.hik.hikService.Common.CommonMethod;
import com.zmykj.hik.hikService.Common.HikUtils;
import com.zmykj.hik.hikService.Service.Alarm.EAlarm;
import com.zmykj.hik.hikService.Service.CMS.ECMS;
import com.zmykj.hik.hikService.Service.CMS.OnlineDevManager;
import com.zmykj.hik.hikService.Service.ISAPI.TransportISAPI;
import com.zmykj.hik.hikService.Service.Storage.ESS;
import com.zmykj.hik.hikService.entity.EmployeeNo;
import com.zmykj.hik.hikService.entity.HikUserInfo;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.*;

/**
 * @author LengChen
 * @version 1.0
 * @date 2021/5/14
 */
@Configuration
public class MainController {

    /**
     * 初始化服务
     */
    @PostConstruct
    public void StartGlobalInit(){
        //初始化
        GlobalController.InitLocalConfig();
        //拉取服务器监听参数
        //初始化CMS服务信息
        CommonMethod.ByteCopy(HikConfig.CMS_IP.getBytes(), CommonMethod.GetListenInfo().struCMSListenParam.struAddress.szIP);
        CommonMethod.GetListenInfo().struCMSListenParam.struAddress.wPort = HikConfig.CMS_PORT.shortValue();

        //初始化AMS报警信息
        CommonMethod.GetListenInfo().struAMSListenParam.byUseCmsPort = HikConfig.AMS_ByUseCmsPort.byteValue();
        CommonMethod.GetListenInfo().struAMSListenParam.byProtocolType = HikConfig.AMS_ByProtocolType.byteValue();
        CommonMethod.ByteCopy(HikConfig.AMS_IP.getBytes(), CommonMethod.GetListenInfo().struAMSListenParam.struAddress.szIP);
        CommonMethod.GetListenInfo().struAMSListenParam.struAddress.wPort = HikConfig.AMS_PORT.shortValue();
        CommonMethod.GetListenInfo().struAMSListenParam.dwKeepAliveSec = HikConfig.AMS_DwKeepAliveSec;
        CommonMethod.GetListenInfo().struAMSListenParam.dwTimeOutCount = HikConfig.AMS_DwTimeOutCount;

        //初始化KMS配置信息
        CommonMethod.ByteCopy(HikConfig.KMS_Username.getBytes(), CommonMethod.GetListenInfo().struSSListenParam.szKMS_UserName);
        CommonMethod.ByteCopy(HikConfig.KMS_Password.getBytes(), CommonMethod.GetListenInfo().struSSListenParam.szKMS_Password);
        CommonMethod.ByteCopy(HikConfig.KMS_AccessKey.getBytes(), CommonMethod.GetListenInfo().struSSListenParam.szAccessKey);
        CommonMethod.ByteCopy(HikConfig.KMS_SecretKey.getBytes(), CommonMethod.GetListenInfo().struSSListenParam.szSecretKey);
        CommonMethod.ByteCopy(HikConfig.KMS_IP.getBytes(), CommonMethod.GetListenInfo().struSSListenParam.struAddress.szIP);
        CommonMethod.GetListenInfo().byCallbackType = HikConfig.byCallbackType.byteValue();
        CommonMethod.GetListenInfo().struSSListenParam.byHttps   = HikConfig.AMS_IsClouldHttps.byteValue();
        CommonMethod.GetListenInfo().struSSListenParam.struAddress.wPort = HikConfig.KMS_PORT.shortValue();
        CommonMethod.GetListenInfo().struSSListenParam.bySecurityMode = HikConfig.AMS_BySecurityMode.byteValue();

        /**
         * 初始化系统配置信息
         */
        CommonClass.NET_EHOME_SERVER_INFO_V50 strEhomeServerInfo = new CommonClass.NET_EHOME_SERVER_INFO_V50();
        strEhomeServerInfo.read();
        CommonMethod.ByteCopy(HikConfig.AMS_IP.getBytes(), strEhomeServerInfo.struUDPAlarmSever.szIP);
        CommonMethod.ByteCopy(HikConfig.AMS_IP.getBytes(), strEhomeServerInfo.struTCPAlarmSever.szIP);
        strEhomeServerInfo.dwAlarmServerType = HikConfig.AMS_ByProtocolType; //报警服务器类型：0- 只支持UDP协议上报，1- 支持UDP、TCP两种协议上报 2-MQTT
        strEhomeServerInfo.struTCPAlarmSever.wPort = HikConfig.AMS_PORT.shortValue();
        strEhomeServerInfo.struUDPAlarmSever.wPort = HikConfig.AMS_PORT.shortValue();
        CommonMethod.ByteCopy(HikConfig.KMS_AccessKey.getBytes(),  strEhomeServerInfo.byClouldAccessKey);
        CommonMethod.ByteCopy(HikConfig.KMS_SecretKey.getBytes(),  strEhomeServerInfo.byClouldSecretKey);
        strEhomeServerInfo.dwPicServerType = 3;
        CommonMethod.ByteCopy(HikConfig.KMS_IP.getBytes(),  strEhomeServerInfo.struPictureSever.szIP);
        strEhomeServerInfo.struPictureSever.wPort = HikConfig.KMS_PORT.shortValue();
        CommonClass.g_struServerInfoV50 = strEhomeServerInfo;
        /*---------------端口映射信息 start---------------*/

        /*------------CMS-----------------*/
            CommonMethod.ByteCopy(CommonMethod.GetListenInfo().struCMSListenParam.struAddress.szIP, CommonMethod.GetListenInfo().struDASParam.szIP);
            CommonMethod.GetListenInfo().struDASParam.wPort = CommonMethod.GetListenInfo().struCMSListenParam.struAddress.wPort;

        /*------------AMS-----------------*/
            CommonMethod.ByteCopy(CommonMethod.GetListenInfo().struAMSListenParam.struAddress.szIP, CommonMethod.GetServerInfo().struTCPAlarmSever.szIP);
            CommonMethod.ByteCopy(CommonMethod.GetListenInfo().struAMSListenParam.struAddress.szIP, CommonMethod.GetServerInfo().struUDPAlarmSever.szIP);
            CommonMethod.GetServerInfo().struUDPAlarmSever.wPort = CommonMethod.GetListenInfo().struAMSListenParam.struAddress.wPort;
            CommonMethod.GetServerInfo().struTCPAlarmSever.wPort = CommonMethod.GetListenInfo().struAMSListenParam.struAddress.wPort;

            CommonMethod.GetServerInfo().dwKeepAliveSec = HikConfig.AMS_DwKeepAliveSec;
            CommonMethod.GetServerInfo().dwTimeOutCount = HikConfig.AMS_DwTimeOutCount;
            CommonMethod.GetServerInfo().dwAlarmServerType = HikConfig.AMS_ByProtocolType;

        /*------------SS-----------------*/
        CommonMethod.ByteCopy(CommonMethod.GetListenInfo().struSSListenParam.struAddress.szIP, CommonMethod.GetServerInfo().struPictureSever.szIP);
        CommonMethod.GetServerInfo().struPictureSever.wPort = CommonMethod.GetListenInfo().struSSListenParam.struAddress.wPort;

        CommonMethod.ByteCopy(CommonMethod.GetListenInfo().struSSListenParam.szAccessKey, CommonMethod.GetServerInfo().byClouldAccessKey);
        CommonMethod.ByteCopy(CommonMethod.GetListenInfo().struSSListenParam.szSecretKey, CommonMethod.GetServerInfo().byClouldSecretKey);
        CommonMethod.GetServerInfo().dwPicServerType = HikConfig.AMS_DwPicServerType;
        CommonMethod.GetServerInfo().byClouldHttps = HikConfig.AMS_IsClouldHttps.byteValue();

        /*------------SMS-----------------*/
       /* CommonMethod.GetListenInfo().bSMSUsePortMapping = getParaToBoolean("LocalConfig[SSPortMapping]");
        if(CommonMethod.GetListenInfo().bSMSUsePortMapping) {
            CommonMethod.ByteCopy(getPara("LocalConfig[PreviewOuterIP]"), CommonMethod.GetListenInfo().struOuterPreviewAddress.szIP);
            CommonMethod.GetListenInfo().struOuterPreviewAddress.wPort = getParaToInt("LocalConfig[PreviewOuterPort]").shortValue();
            CommonMethod.ByteCopy(getPara("LocalConfig[PlaybackOuterIP]"), CommonMethod.GetListenInfo().struOuterPlaybackAddress.szIP);
            CommonMethod.GetListenInfo().struOuterPlaybackAddress.wPort = getParaToInt("LocalConfig[PlaybackOuterPort]").shortValue();
        }else{
            CommonMethod.GetListenInfo().struOuterPreviewAddress = CommonMethod.GetListenInfo().struPreviewListenParam.struIPAdress;
            CommonMethod.GetListenInfo().struOuterPlaybackAddress = CommonMethod.GetListenInfo().struPlaybackListenParam.struIPAddress;
        }*/
        /*---------------端口映射信息 end---------------*/
        try {
            System.out.println("Enter ServerInit");
            OnlineDevManager.g_Devs = new ArrayList<OnlineDevManager.Device>();
            GlobalController.m_serverEAlarm = new EAlarm();
           /* GlobalController.m_serverEStream = new EStream();*/
            GlobalController.m_serverESS    = new ESS();
            GlobalController.m_serverECMS   = new ECMS();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());

        }
        GlobalController.SetInitStatus(true);
    }


    /**
     * 下发人员信息-只能单个下发
     * @param userId 用户ID
     * @param userName 用户姓名
     * @param deviceID 下发的设备号
     * @return
     */
    public static boolean addUser(String userId,String userName,String deviceID){
        long lUserID = HikUtils.checkDeviceID(deviceID);
        if (lUserID != -1)
        {
            String szReqUrl =  "/ISAPI/AccessControl/UserInfo/SetUp?format=json";
            HikUserInfo hikUserInfo = new HikUserInfo();
            hikUserInfo.getUserInfo().setEmployeeNo(userId);
            hikUserInfo.getUserInfo().setName(userName);
            String UserInfoStr = JSONObject.toJSONString(hikUserInfo);
            System.out.println("下发的人员信息==="+UserInfoStr);
            StringBuffer pOutBuffer = new StringBuffer();
            if(!TransportISAPI.PassthroughISAPI(lUserID, "PUT", szReqUrl, UserInfoStr, 5000, pOutBuffer,userName))
            {
                CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" + ECMS.GetCMSInstance().NET_ECMS_GetLastError());
                return false;
            }
            else
            {
                String sOutString = pOutBuffer.toString();
                System.out.println(sOutString);
                JSONObject jsonObject = JSONObject.parseObject(sOutString);
                if(jsonObject.getInteger("statusCode")==1){
                    return true;
                }else{
                    CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough  /ISAPI/AccessControl/UserInfo/SetUp?format=json Error,  errCode is:" +jsonObject.toString());
                }
            }
        }

        return true;
    }


    /**
     * 根据用户ID删除用户数据
     * @param userId 用户ID 
     * @param deviceID 设备ID
     * @return
     */
    public static boolean deleateUser(String userId,String deviceID){
        long lUserID = HikUtils.checkDeviceID(deviceID);
        if (lUserID != -1)
        {
            String szReqUrl =  "/ISAPI/AccessControl/UserInfoDetail/Delete?format=json";
            Map<String,Object> map = new HashMap<>();
            Map<String,Object> UserInfoDetail = new HashMap<>();
            if(StringUtils.isNotBlank(userId)){
                UserInfoDetail.put("mode","byEmployeeNo");
                List<EmployeeNo> EmployeeNoList = new ArrayList<EmployeeNo>();
                EmployeeNoList.add(new EmployeeNo(userId));
                UserInfoDetail.put("EmployeeNoList",EmployeeNoList);
            }else {
                return false;
            }
            map.put("UserInfoDetail",UserInfoDetail);
            String UserInfoStr = JSONObject.toJSONString(map);
            StringBuffer pOutBuffer = new StringBuffer();
            if(!TransportISAPI.PassthroughISAPI(lUserID, "PUT", szReqUrl, UserInfoStr, 5000, pOutBuffer))
            {
                CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" + ECMS.GetCMSInstance().NET_ECMS_GetLastError());
                return false;
            }
            else
            {
                String sOutString = pOutBuffer.toString();
                System.out.println(sOutString);
                JSONObject jsonObject = JSONObject.parseObject(sOutString);
                if(jsonObject.getInteger("statusCode")==1){
                    deleteFaceImage(userId,deviceID);
                    return true;
                }else{
                    CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" +jsonObject.toString());
                }
            }
        }

        return true;
    }


    /**
     * 下发指纹信息
     * @param userId 用户ID
     * @param deviceID 设备ID
     * @param fingerData 指纹ID
     * @return
     */
    public static AjaxResult downUserFingerprint(String userId,String deviceID,String fingerData){

        long lUserID = HikUtils.checkDeviceID(deviceID);
        if (lUserID != -1)
        {
            String szReqUrl =  "/ISAPI/AccessControl/FingerPrint/SetUp?format=json";
            Map<String,Object> map = new HashMap<>();
            Map<String,Object> UserInfo = new HashMap<>();
            if(StringUtils.isNotBlank(userId)){
                UserInfo.put("employeeNo",userId);
                int[] arrays = new int[]{1};
                UserInfo.put("enableCardReader",arrays);
                UserInfo.put("fingerPrintID",1);
                UserInfo.put("fingerType","normalFP");
                UserInfo.put("fingerData",fingerData);
                map.put("FingerPrintCfg",UserInfo);
            }else {
                return AjaxResult.error("用户信息错误");
            }
            String UserInfoStr = JSONObject.toJSONString(map);
            StringBuffer pOutBuffer = new StringBuffer();
            if(!TransportISAPI.PassthroughISAPI(lUserID, "POST", szReqUrl, UserInfoStr, 5000, pOutBuffer))
            {
                CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" + ECMS.GetCMSInstance().NET_ECMS_GetLastError());
                return AjaxResult.error("设备接口异常");
            }
            else
            {
                String sOutString = pOutBuffer.toString();
                System.out.println(sOutString);
                JSONObject jsonObject = JSONObject.parseObject(sOutString);
                if(jsonObject.getJSONObject("FingerPrintStatus").getJSONArray("StatusList").getJSONObject(0).getInteger("cardReaderRecvStatus") == 1){
                    return AjaxResult.success();
                }else{
                    CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" +jsonObject.toString());
                }
            }
        }
        return AjaxResult.error("系统繁忙");
    }


    /**
     * 下发人脸信息
     * @param userId 用户ID
     * @param deviceID 设备ID
     * @param imageUrl 人脸图片
     * @return
     */
    public static AjaxResult downUserFaceImage(String userId, String userName, String deviceID, String imageUrl){
        long lUserID = HikUtils.checkDeviceID(deviceID);
        if (lUserID != -1)
        {
            String szReqUrl =  "POST /ISAPI/Intelligent/FDLib/FaceDataRecord?format=json";
            Map<String,Object> UserInfo = new HashMap<>();
            if(StringUtils.isNotBlank(userId)){
                UserInfo.put("faceURL",imageUrl);
                UserInfo.put("faceLibType","blackFD");
                UserInfo.put("FDID","1");
                UserInfo.put("FPID",userId);
                UserInfo.put("name",userName);
                UserInfo.put("gender","unknown");
                UserInfo.put("bornTime","2020-04-11T16:08:08.868+08:00");
            }else {
                return AjaxResult.error("用户信息错误");
            }
            String UserInfoStr = JSONObject.toJSONString(UserInfo);
            StringBuffer pOutBuffer = new StringBuffer();
            if(!TransportISAPI.PassthroughISAPI(lUserID, "POST", szReqUrl, UserInfoStr, 5000, pOutBuffer,userName))
            {
                CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" + ECMS.GetCMSInstance().NET_ECMS_GetLastError());
                return AjaxResult.error("设备接口异常");
            }
            else
            {
                String sOutString = pOutBuffer.toString();
                System.out.println(sOutString);
                JSONObject jsonObject = JSONObject.parseObject(sOutString);
                if(jsonObject.getInteger("statusCode") == 1){
                    return AjaxResult.success();
                }else{
                    if("deviceUserAlreadyExistFace".equals(jsonObject.getString("subStatusCode"))){
                        return updateUserFaceImage(userId,userName,deviceID,imageUrl);
                    }else if("employeeNoNotExist".equals(jsonObject.getString("subStatusCode"))){
                        return AjaxResult.warn("人员信息不存在");
                    }else if("picFormatError".equals(jsonObject.getString("picFormatError"))){
                        return AjaxResult.error("验证失败，请重试");
                    }
                    CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" +jsonObject.toString());
                }
            }
        }
        return AjaxResult.error("系统繁忙");
    }

    /**
     * 修改人脸考勤信息
     * @param userId
     * @param userName
     * @param deviceID
     * @param imageUrl
     * @return
     */
    public static AjaxResult updateUserFaceImage(String userId,String userName,String deviceID,String imageUrl){
        long lUserID = HikUtils.checkDeviceID(deviceID);
        if (lUserID != -1)
        {
            String szReqUrl =  "PUT /ISAPI/Intelligent/FDLib/FDSearch?format=json&FDID=1&FPID="+userId+"&faceLibType=blackFD";
            Map<String,Object> UserInfo = new HashMap<>();
            if(StringUtils.isNotBlank(userId)){
                UserInfo.put("faceURL",imageUrl);
                UserInfo.put("faceLibType","blackFD");
                UserInfo.put("name",userName);
                UserInfo.put("gender","unknown");
                UserInfo.put("bornTime","2020-04-11T16:08:08.868+08:00");
            }else {
                return AjaxResult.error("用户信息错误");
            }
            String UserInfoStr = JSONObject.toJSONString(UserInfo);
            StringBuffer pOutBuffer = new StringBuffer();
            if(!TransportISAPI.PassthroughISAPI(lUserID, "PUT", szReqUrl, UserInfoStr, 5000, pOutBuffer,userName))
            {
                CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" + ECMS.GetCMSInstance().NET_ECMS_GetLastError());
                return AjaxResult.error("设备接口异常");
            }else{
                String sOutString = pOutBuffer.toString();
                System.out.println(sOutString);
                JSONObject jsonObject = JSONObject.parseObject(sOutString);
                if(jsonObject.getInteger("statusCode") == 1){
                    return AjaxResult.success();
                }
            }
        }
        return AjaxResult.error("系统繁忙");
    }


    /**
     * 删除人脸信息
     * @param userId 用户ID
     * @param deviceID 设备ID
     * @return
     */
    public static boolean deleteFaceImage(String userId,String deviceID){
        long lUserID = HikUtils.checkDeviceID(deviceID);
        if (lUserID != -1)
        {
            String szReqUrl =  "PUT /ISAPI/Intelligent/FDLib/FDSearch/Delete?format=json&FDID=1&faceLibType=blackFD";
            Map<String,Object> map = new HashMap<>();
            Map<String,Object> UserInfo = new HashMap<>();
            List<Map> mapList = new ArrayList<>();
            if(StringUtils.isNotBlank(userId)){
                UserInfo.put("value",userId);
                mapList.add(UserInfo);
                map.put("FPID",mapList);
            }else {
                return false;
            }
            String UserInfoStr = JSONObject.toJSONString(map);
            StringBuffer pOutBuffer = new StringBuffer();
            if(!TransportISAPI.PassthroughISAPI(lUserID, "PUT", szReqUrl, UserInfoStr, 5000, pOutBuffer))
            {
                CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" + ECMS.GetCMSInstance().NET_ECMS_GetLastError());
                return false;
            }
            else
            {
                String sOutString = pOutBuffer.toString();
                System.out.println(sOutString);
                JSONObject jsonObject = JSONObject.parseObject(sOutString);
                if(jsonObject.getInteger("statusCode") == 1){
                    return true;
                }else{
                    CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" +jsonObject.toString());
                }
            }
        }
        return false;
    }




    /**
     * 获取人员的指纹信息
     * @param userId
     * @param deviceID
     * @return
     */
    public static String getUserFingerprint(String userId,String deviceID){
        long lUserID = HikUtils.checkDeviceID(deviceID);
        if (lUserID != -1)
        {
            String szReqUrl =  "POST /ISAPI/AccessControl/FingerPrintUpload?format=json";
            Map<String,Object> map = new HashMap<>();
            Map<String,Object> UserInfo = new HashMap<>();
            if(StringUtils.isNotBlank(userId)){
                UserInfo.put("searchID", UUID.randomUUID());
                UserInfo.put("employeeNo",userId);
                map.put("FingerPrintCond",UserInfo);
            }else {
                return null;
            }
            String UserInfoStr = JSONObject.toJSONString(map);
            StringBuffer pOutBuffer = new StringBuffer();
            if(!TransportISAPI.PassthroughISAPI(lUserID, "POST", szReqUrl, UserInfoStr, 5000, pOutBuffer))
            {
                CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" + ECMS.GetCMSInstance().NET_ECMS_GetLastError());
                return null;
            }
            else
            {
                String sOutString = pOutBuffer.toString();
                JSONObject jsonObject = JSONObject.parseObject(sOutString);
                System.out.println(jsonObject.toString());
                if(jsonObject.getJSONObject("FingerPrintInfo").getString("status").equals("OK")){
                    return jsonObject.getJSONObject("FingerPrintInfo").getJSONArray("FingerPrintList").getJSONObject(0).getString("fingerData");
                }
            }
        }
        return null;
    }

    /**
     * 获取人员的人脸图片
     * @param userId 用户ID
     * @param deviceID 设备ID
     * @return
     */
    public static String getUserFaceImageUrl(String userId,String deviceID){
        long lUserID = HikUtils.checkDeviceID(deviceID);
        if (lUserID != -1)
        {
            String szReqUrl =  "POST /ISAPI/Intelligent/FDLib/FDSearch?format=json";
            Map<String,Object> UserInfo = new HashMap<>();
            if(StringUtils.isNotBlank(userId)){
                UserInfo.put("searchResultPosition", 0);
                UserInfo.put("maxResults", 10);
                UserInfo.put("faceLibType", "blackFD");
                UserInfo.put("FDID", "1");
                UserInfo.put("FPID", userId);
            }else {
                return null;
            }
            String UserInfoStr = JSONObject.toJSONString(UserInfo);
            StringBuffer pOutBuffer = new StringBuffer();
            if(!TransportISAPI.PassthroughISAPI(lUserID, "POST", szReqUrl, UserInfoStr, 5000, pOutBuffer))
            {
                CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" + ECMS.GetCMSInstance().NET_ECMS_GetLastError());
                return null;
            }
            else
            {
                String sOutString = pOutBuffer.toString();
                JSONObject jsonObject = JSONObject.parseObject(sOutString);
                if(jsonObject.getString("responseStatusStrg").equals("OK")){
                    return jsonObject.getJSONArray("MatchList").getJSONObject(0).getString("faceURL");
                }
            }
        }
        return null;
    }

    /**
     * 删除设备的全部用户信息
     * @param deviceID
     * @return
     */
    public static Boolean deleateAllUser(String deviceID) {
        long lUserID = HikUtils.checkDeviceID(deviceID);
        if (lUserID != -1)
        {
            String szReqUrl =  "/ISAPI/AccessControl/UserInfoDetail/Delete?format=json";
            Map<String,Object> map = new HashMap<>();
            Map<String,Object> UserInfoDetail = new HashMap<>();
            UserInfoDetail.put("mode","all");
            map.put("UserInfoDetail",UserInfoDetail);
            String UserInfoStr = JSONObject.toJSONString(map);
            StringBuffer pOutBuffer = new StringBuffer();
            if(!TransportISAPI.PassthroughISAPI(lUserID, "PUT", szReqUrl, UserInfoStr, 5000, pOutBuffer))
            {
                CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" + ECMS.GetCMSInstance().NET_ECMS_GetLastError());
                return false;
            }
            else
            {
                String sOutString = pOutBuffer.toString();
                System.out.println(sOutString);
                JSONObject jsonObject = JSONObject.parseObject(sOutString);
                if(jsonObject.getInteger("statusCode")==1){
                    return true;
                }else{
                    CommonMethod.logRecord("Error", "NET_ECMS_ISAPIPassThrough Error, errCode is:" +jsonObject.toString());
                }
            }
        }
        return true;
    }
}
